From ef860cf6815dceb0a806a08b2118390830ccdae0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 4 Jun 2025 16:57:56 +0700 Subject: purchase pricelist and schema invoice --- fixco_custom/models/__init__.py | 1 + fixco_custom/models/account_move.py | 4 +++- fixco_custom/models/purchase_pricelist.py | 18 ++++++++++++++++++ fixco_custom/models/sale.py | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 fixco_custom/models/purchase_pricelist.py (limited to 'fixco_custom/models') diff --git a/fixco_custom/models/__init__.py b/fixco_custom/models/__init__.py index a6fc1c9..c362a04 100755 --- a/fixco_custom/models/__init__.py +++ b/fixco_custom/models/__init__.py @@ -8,3 +8,4 @@ from . import barcoding_product from . import sale_order_multi_invoices from . import account_move from . import upload_payments +from . import purchase_pricelist diff --git a/fixco_custom/models/account_move.py b/fixco_custom/models/account_move.py index bf7ffc9..3f52319 100644 --- a/fixco_custom/models/account_move.py +++ b/fixco_custom/models/account_move.py @@ -15,4 +15,6 @@ class AccountMove(models.Model): _inherit = 'account.move' invoice_marketplace = fields.Char('Invoice Marketplace') - address = fields.Char('Address') \ No newline at end of file + address = fields.Char('Address') + sale_id = fields.Many2one('sale.order', string='Sale Order') + picking_id = fields.Many2one('stock.picking', string='Picking') \ No newline at end of file diff --git a/fixco_custom/models/purchase_pricelist.py b/fixco_custom/models/purchase_pricelist.py new file mode 100644 index 0000000..2d0a77c --- /dev/null +++ b/fixco_custom/models/purchase_pricelist.py @@ -0,0 +1,18 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import datetime, timedelta +from pytz import timezone + +class PurchasePricelist(models.Model): + _name = 'purchase.pricelist' + _rec_name = 'product_id' + _inherit = ['mail.thread', 'mail.activity.mixin'] + + name = fields.Char(string='Name', compute="_compute_name") + product_id = fields.Many2one('product.product', string="Product", required=True) + vendor_id = fields.Many2one('res.partner', string="Vendor", required=True) + price = fields.Float(string='Price', required=True) + + @api.depends('product_id', 'vendor_id') + def _compute_name(self): + self.name = self.vendor_id.name + ', ' + self.product_id.name \ No newline at end of file diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py index 6d7a7e6..b36f4b5 100755 --- a/fixco_custom/models/sale.py +++ b/fixco_custom/models/sale.py @@ -29,11 +29,15 @@ class SaleOrder(models.Model): if not journal: raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % (self.company_id.name, self.company_id.id)) + done_pickings = self.picking_ids.filtered(lambda p: p.state == 'done').sorted(key='create_date') invoice_vals = { 'ref': self.client_order_ref or '', 'move_type': 'out_invoice', 'narration': self.note, 'invoice_marketplace': self.invoice_mp, + 'address': self.address, + 'sale_id': self.id, + 'picking_id': done_pickings[0] if done_pickings else False, 'currency_id': self.pricelist_id.currency_id.id, 'campaign_id': self.campaign_id.id, 'medium_id': self.medium_id.id, -- cgit v1.2.3