meta_receipt: Accept invoice in lieu of receipt for credit card charges.
This commit is contained in:
		
							parent
							
								
									7cac21b780
								
							
						
					
					
						commit
						381160f0de
					
				
					 2 changed files with 22 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -38,21 +38,25 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook):
 | 
			
		|||
    def post_run(self, txn: Transaction, post: data.Posting) -> errormod.Iter:
 | 
			
		||||
        try:
 | 
			
		||||
            self._check_links(txn, post, 'receipt')
 | 
			
		||||
        except errormod.Error as receipt_error:
 | 
			
		||||
            # Outgoing check may omit a receipt if they have a check link
 | 
			
		||||
            # instead.
 | 
			
		||||
            if ':Check' not in post.account:
 | 
			
		||||
        except errormod.Error as error:
 | 
			
		||||
            receipt_error = error
 | 
			
		||||
        else:
 | 
			
		||||
            return
 | 
			
		||||
        if post.account.is_checking():
 | 
			
		||||
            fallback_key = 'check'
 | 
			
		||||
        elif (post.account.is_under('Liabilities:CreditCard')
 | 
			
		||||
              and (post.units.number or 0) < 0):
 | 
			
		||||
            fallback_key = 'invoice'
 | 
			
		||||
        else:
 | 
			
		||||
            yield receipt_error
 | 
			
		||||
            return
 | 
			
		||||
        try:
 | 
			
		||||
            self._check_links(txn, post, fallback_key)
 | 
			
		||||
        except errormod.Error as fallback_error:
 | 
			
		||||
            if (receipt_error.message.endswith(f" missing {self.METADATA_KEY}")
 | 
			
		||||
                and fallback_error.message.endswith(f" missing {fallback_key}")):
 | 
			
		||||
                receipt_error.message += f" or {fallback_key}"
 | 
			
		||||
                yield receipt_error
 | 
			
		||||
            else:
 | 
			
		||||
                try:
 | 
			
		||||
                    self._check_links(txn, post, 'check')
 | 
			
		||||
                except errormod.Error as check_error:
 | 
			
		||||
                    if (receipt_error.message.endswith(" missing receipt")
 | 
			
		||||
                        and check_error.message.endswith(" missing check")):
 | 
			
		||||
                        check_error.message = check_error.message.replace(
 | 
			
		||||
                            " missing check", " missing receipt or check",
 | 
			
		||||
                        )
 | 
			
		||||
                        yield check_error
 | 
			
		||||
                    else:
 | 
			
		||||
                        yield receipt_error
 | 
			
		||||
                        yield check_error
 | 
			
		||||
                yield receipt_error
 | 
			
		||||
                yield fallback_error
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,6 +60,8 @@ ACCOUNTS = [AccountForTesting._make(t) for t in [
 | 
			
		|||
    ('Assets:Cash', PostType.BOTH, None),
 | 
			
		||||
    ('Assets:Checking', PostType.BOTH, 'check'),
 | 
			
		||||
    ('Assets:Savings', PostType.BOTH, None),
 | 
			
		||||
    ('Liabilities:CreditCard', PostType.CREDIT, None),
 | 
			
		||||
    ('Liabilities:CreditCard', PostType.DEBIT, 'invoice'),
 | 
			
		||||
]]
 | 
			
		||||
 | 
			
		||||
ACCOUNTS_WITH_FALLBACKS = [acct for acct in ACCOUNTS if acct.fallback_meta]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue